clear all
set more off
cd ""

use "sample.dta", clear
gen first_treat = 1 + (mdy(csm_month,csm_day,2020) - mdy(1,10,2020))

***********
* Panel A1
***********

csdid in_confn14 if faction == 1, ivar(city_code) time(time) gvar(first_treat) agg(event) long2 wboot rseed(10101) pointwise
nlcom (_b[Tp0]+_b[Tp1]+_b[Tp2]+_b[Tp3]+_b[Tp4]+_b[Tp5]+_b[Tp6]+_b[Tp7]+_b[Tp8]+_b[Tp9]+_b[Tp10])/11

csdid d_movewithin if faction == 1, ivar(city_code) time(time) gvar(first_treat) agg(event) long2 wboot rseed(10101) pointwise
nlcom (_b[Tp0]+_b[Tp1]+_b[Tp2]+_b[Tp3]+_b[Tp4]+_b[Tp5]+_b[Tp6]+_b[Tp7]+_b[Tp8]+_b[Tp9]+_b[Tp10])/11

csdid bdindexS7_std if faction == 1, ivar(city_code) time(time) gvar(first_treat) agg(event) long2 wboot rseed(10101) pointwise
nlcom (_b[Tp0]+_b[Tp1]+_b[Tp2]+_b[Tp3]+_b[Tp4]+_b[Tp5]+_b[Tp6]+_b[Tp7]+_b[Tp8]+_b[Tp9]+_b[Tp10])/11

***********
* Panel A2
***********

csdid in_confn14 if faction == 0, ivar(city_code) time(time) gvar(first_treat) agg(event) long2 wboot rseed(10101) pointwise
nlcom (_b[Tp0]+_b[Tp1]+_b[Tp2]+_b[Tp3]+_b[Tp4]+_b[Tp5]+_b[Tp6]+_b[Tp7]+_b[Tp8]+_b[Tp9]+_b[Tp10])/11

csdid d_movewithin if faction == 0, ivar(city_code) time(time) gvar(first_treat) agg(event) long2 wboot rseed(10101) pointwise
nlcom (_b[Tp0]+_b[Tp1]+_b[Tp2]+_b[Tp3]+_b[Tp4]+_b[Tp5]+_b[Tp6]+_b[Tp7]+_b[Tp8]+_b[Tp9]+_b[Tp10])/11

csdid bdindexS7_std if faction == 0, ivar(city_code) time(time) gvar(first_treat) agg(event) long2 wboot rseed(10101) pointwise
nlcom (_b[Tp0]+_b[Tp1]+_b[Tp2]+_b[Tp3]+_b[Tp4]+_b[Tp5]+_b[Tp6]+_b[Tp7]+_b[Tp8]+_b[Tp9]+_b[Tp10])/11

***********
* Panel B1
***********

tab prov_code, gen(prov_code)
forvalues i = 1/24 {
gen provXtime`i' = prov_code`i'*time
gen provXsqtime`i' = prov_code`i'*(time^2)
}

bootstrap _b[pre5] _b[pre4] _b[pre3] _b[pre2] _b[pre1] _b[tau0] _b[tau1] _b[tau2] _b[tau3] _b[tau4] _b[tau5] _b[tau6] _b[tau7] _b[tau8] _b[tau9] _b[tau10], reps(2000) seed(12345): did_imputation in_confn14 city_code time first_treat if faction == 1, controls(wdsp temp prcp provXtime*) horizons(0/10) autosample pretrends(5) nose
nlcom (_b[_bs_6]+_b[_bs_7]+_b[_bs_8]+_b[_bs_9]+_b[_bs_10]+_b[_bs_11]+_b[_bs_12]+_b[_bs_13]+_b[_bs_14]+_b[_bs_15]+_b[_bs_16])/11

bootstrap _b[pre5] _b[pre4] _b[pre3] _b[pre2] _b[pre1] _b[tau0] _b[tau1] _b[tau2] _b[tau3] _b[tau4] _b[tau5] _b[tau6] _b[tau7] _b[tau8] _b[tau9] _b[tau10], reps(2000) seed(12345): did_imputation d_movewithin city_code time first_treat if faction == 1, controls(wdsp temp prcp provXtime* provXsqtime*) horizons(0/10) autosample pretrends(5) nose
nlcom (_b[_bs_6]+_b[_bs_7]+_b[_bs_8]+_b[_bs_9]+_b[_bs_10]+_b[_bs_11]+_b[_bs_12]+_b[_bs_13]+_b[_bs_14]+_b[_bs_15]+_b[_bs_16])/11

bootstrap _b[pre5] _b[pre4] _b[pre3] _b[pre2] _b[pre1] _b[tau0] _b[tau1] _b[tau2] _b[tau3] _b[tau4] _b[tau5] _b[tau6] _b[tau7] _b[tau8] _b[tau9] _b[tau10], reps(2000) seed(12345): did_imputation bdindexS7_std city_code time first_treat if faction == 1, controls(wdsp temp prcp provXtime*) horizons(0/10) autosample pretrends(5) nose
nlcom (_b[_bs_6]+_b[_bs_7]+_b[_bs_8]+_b[_bs_9]+_b[_bs_10]+_b[_bs_11]+_b[_bs_12]+_b[_bs_13]+_b[_bs_14]+_b[_bs_15]+_b[_bs_16])/11

***********
* Panel B2
***********

bootstrap _b[pre5] _b[pre4] _b[pre3] _b[pre2] _b[pre1] _b[tau0] _b[tau1] _b[tau2] _b[tau3] _b[tau4] _b[tau5] _b[tau6] _b[tau7] _b[tau8] _b[tau9] _b[tau10], reps(2000) seed(12345): did_imputation in_confn14 city_code time first_treat if faction == 0, controls(wdsp temp prcp provXtime*) horizons(0/10) autosample pretrends(5) nose
nlcom (_b[_bs_6]+_b[_bs_7]+_b[_bs_8]+_b[_bs_9]+_b[_bs_10]+_b[_bs_11]+_b[_bs_12]+_b[_bs_13]+_b[_bs_14]+_b[_bs_15]+_b[_bs_16])/11

bootstrap _b[pre5] _b[pre4] _b[pre3] _b[pre2] _b[pre1] _b[tau0] _b[tau1] _b[tau2] _b[tau3] _b[tau4] _b[tau5] _b[tau6] _b[tau7] _b[tau8] _b[tau9] _b[tau10], reps(2000) seed(12345): did_imputation d_movewithin city_code time first_treat if faction == 0, controls(wdsp temp prcp provXtime* provXsqtime*) horizons(0/10) autosample pretrends(5) nose
nlcom (_b[_bs_6]+_b[_bs_7]+_b[_bs_8]+_b[_bs_9]+_b[_bs_10]+_b[_bs_11]+_b[_bs_12]+_b[_bs_13]+_b[_bs_14]+_b[_bs_15]+_b[_bs_16])/11

bootstrap _b[pre5] _b[pre4] _b[pre3] _b[pre2] _b[pre1] _b[tau0] _b[tau1] _b[tau2] _b[tau3] _b[tau4] _b[tau5] _b[tau6] _b[tau7] _b[tau8] _b[tau9] _b[tau10], reps(2000) seed(12345): did_imputation bdindexS7_std city_code time first_treat if faction == 0, controls(wdsp temp prcp provXtime*) horizons(0/10) autosample pretrends(5) nose
nlcom (_b[_bs_6]+_b[_bs_7]+_b[_bs_8]+_b[_bs_9]+_b[_bs_10]+_b[_bs_11]+_b[_bs_12]+_b[_bs_13]+_b[_bs_14]+_b[_bs_15]+_b[_bs_16])/11
